﻿using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.Controllers;
using System;
using System.Reflection;

namespace Cms.Core.Infrastructure.Extension
{
   public  static class ControllerExtensions
    {


        public static TAttribute GetAttribute<TAttribute>(this ActionModel actionModel, bool inherit = true) where TAttribute: Attribute
        {

            return actionModel.Controller.ControllerType.GetCustomAttribute<TAttribute>(inherit);
        }


        public static TypeInfo GetControllerType(this ActionModel actionModel)
        {
            return actionModel.Controller.ControllerType;
        }

        public static TypeInfo AsTypeInfo(this ControllerActionDescriptor controllerActionDescriptor)
        {
            return controllerActionDescriptor.ControllerTypeInfo;
        }

    }
}
